<?php
require_once("include.php");
session_start();

function doit() {
global $drawdown ;
echo "<script src='wz_jsgraphics.js'></script>";
echo "<div id = 'canvas'></div>";
echo "<script>";
echo "var jg_doc = new jsGraphics('canvas')\n";
echo "jg_doc.setFont('arial', '11px', Font.BOLD)\n"; 
$prod = 'PRODUCT'; 
$drawdown = 20 ;
drawbom($prod,1,0);
echo "jg_doc.paint();\n";
echo "</script>"; 
}
doit();
function drawbom($prod,$level,$downparent) {
 global $drawdown;
 $sql = "select subproduct from productbuilds where itemid = '$prod'";
 $list = sqlreadkeyarray($sql);
 echo ("jg_doc.setColor('#0000FF')\n");
 echo ("jg_doc.fillRect($level*100+15,$drawdown,70,19)\n");
 if ($downparent != 0) {
  echo ("jg_doc.drawLine(($level-1)*100+85,$downparent+7,$level*100+15,$drawdown+7)\n");
 }
 echo ("jg_doc.setColor('#FFFFFF')\n");
 echo ("jg_doc.drawStringRect('$prod',$level*100,$drawdown+2,100,'center')\n");

 $downparent = $drawdown;
 if ($list) {
   foreach ($list as $productid=>$item) {
    drawbom($productid,$level+1,$downparent);
    $drawdown = $drawdown + 20;
   }
   $drawdown = $drawdown - 20;
 }
}
?>
